/**********************************************
** @Des: This file ...
** @Author: xiaomeng79
** @Date:   17-11-17 上午9:38
***********************************************/
package models

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/mattn/go-sqlite3"
	"github.com/astaxie/beego/validation"
)

func Init() {
	dbname := beego.AppConfig.String("db.name")
	orm.RegisterDataBase("default", "sqlite3", dbname,20,30)
	orm.RegisterModel(new(Email))
	orm.RunSyncdb("default", false, true)

	if beego.AppConfig.String("runmode") == "dev" {
		orm.Debug = true
	}
	//设置默认的验证返回值
	validation.SetDefaultMessage(DefaultMessage())
}

func DefaultMessage() map[string]string {
	return map[string]string{
		"Required":     "不能为空",
		"Min":          "最小值 %d",
		"Max":          "最大值 %d",
		"Range":        "数值的范围 %d 到 %d",
		"MinSize":      "最小长度为 %d",
		"MaxSize":      "最大长度为 %d",
		"Length":       "有效长度为 %d",
		"Alpha":        "必须是alpha字符",
		"Numeric":      "必须是数字",
		"AlphaNumeric": "必须是alpha 字符或数字",
		"Match":        "必须匹配 %s",
		"NoMatch":      "不能匹配 %s",
		"AlphaDash":    "必须是alpha 字符或数字或横杠",
		"Email":        "不是有效的邮箱",
		"IP":           "不是有效的IP",
		"Base64":       "不是有效的Base64编码",
		"Mobile":       "不是有效的手机号码",
		"Tel":          "不是有效的电话号码",
		"Phone":        "不是有效的手机号或固定电话号",
		"ZipCode":      "不是有效的邮政编码",
	}


}